package com.ljy.my_study.java.thread.threadlocal;

import java.util.concurrent.*;

/**
 * @author lijunying
 * @date 2021/6/17 9:59
 */
public class InheritableThreadLocalTestMain {

    //不能传给子线程
    private static ThreadLocal<String> threadLocal=new ThreadLocal<>();
    //可以将threadLocal的值传给子线程
    private static InheritableThreadLocal<String> inheritableThreadLocal=new InheritableThreadLocal<>();

    public static void main(String[] args) {
        threadLocal.set("James");
        inheritableThreadLocal.set("James");
        InheritableThreadLocalTestTask task=new InheritableThreadLocalTestTask(threadLocal,inheritableThreadLocal);
        //阿里不建议使用Executors，要明确创建线程池里面的配置
        ThreadPoolExecutor executor=new ThreadPoolExecutor(10, 10, 1L, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(100));
        executor.execute(task);
        executor.shutdown();
    }
}
